{% extends "base.html" %}
{% load post_tags %}
{% load highlight %}


{% block title %}My blog{% endblock %}

{% block content %}
    <h1>Search results</h1>
    <div class="module">
        {% if query %}
            {% for post in posts %}
                <div class="course-info">
                    <h2>{% highlight post.title with query max_length 200 %}</h2>
                    {% with post.body|djangomarkdown as body %}
                        {% highlight body with query max_length 200 %}
                    {% endwith %}
                    <p>
                        <a href="{% url "post_edit"  pk=post.id %}">Edit</a>
                        <a href="{% url "post_delete"  pk=post.id %}">Delete</a>
                        <a href="{% url "post_detail"  pk=post.id %}">Detail</a>
                        Tags:
                        {% for tag in post.tags.all %}
                            <a href="{% url "post_list_by_tag" tag.name %}">
                                {{ tag.name }}
                            </a>
                            {% if not forloop.last %}, {% endif %}
                        {% endfor %}
                    </p>
                </div>
            {% empty %}
                <div class="course-info">
                <p>No results found.</p>
                </div>
            {% endfor %}

            <div class="pagination">
    <span class="step-links">
        {% if posts.has_previous %}
            <a href="?q={{ query }}&page={{ posts.previous_page_number }}">Previous</a>
        {% endif %}
        <span class="current">
            Page {{ posts.number }} of {{ posts.paginator.num_pages }}.
        </span>
        {% if posts.has_next %}
            <a href="?q={{ query }}&page={{ posts.next_page_number }}">Next</a>
        {% endif %}
    </span>
            </div>
            </div>
        {% endif %}
{% endblock %}
{% block sidebar %}
    <form action="" method="post">
        {{ form.search }}
        {% csrf_token %}
        <input type="submit" value="Search">
    </form>
{% endblock %}
{% block sidebar_second %}
    <ul>
        {% for post in tag_lists %}
            {% for tag in post.tags.all %}
                <li style=" float:left;margin: 1px 5px;list-style:none;display:block;white-space: nowrap;width: 40%"><a
                        href="{% url "post_list_by_tag" tag.name %}">
                    {{ tag.name }}({{ forloop.counter }})
                </a></li>
                {% if not forloop.last %}, {% endif %}
            {% endfor %}
        {% endfor %}
    </ul>
{% endblock %}